package com.chunfeng.mypen.controller;

import com.chunfeng.mypen.entity.Log;
import com.chunfeng.mypen.result.JsonRequest;
import com.chunfeng.mypen.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 日志控制层
 *
 * @author by 春风能解释
 * <p>
 * 2023/11/22
 */
@RestController
@RequestMapping("/log")
@Api(value = "日志控制层", tags = "日志访问操作接口")
public class LogController {

    /**
     * 日志业务层接口
     */
    @Autowired
    private LogService logService;

    /**
     * 条件查询日志
     *
     * @param current 当前页
     * @param size    每页长度
     * @param log     条件
     * @return JSON
     */
    @GetMapping
    @ApiOperation(value = "条件查询日志")
    public JsonRequest<List<Log>> lookAllLog(
            @ApiParam(value = "当前页数", required = true)
            @RequestParam Integer current,
            @ApiParam(value = "每页长度", required = true)
            @RequestParam Integer size,
            @ApiParam(value = "条件", required = true)
            Log log) {
        return logService.lookAllLog(current, size, log);
    }

    /**
     * 新增一条日志信息
     *
     * @param log 日志信息
     * @return JSON
     */
    @PostMapping
    @ApiOperation(value = "新增一条日志信息")
    public JsonRequest<Integer> insertOneLog(
            @ApiParam(value = "待添加的日志信息", required = true)
            @RequestBody Log log) {
        return logService.insertOneLog(log);
    }

    /**
     * 更新一条日志
     *
     * @param log 日志信息
     * @return JSON
     */
    @PutMapping
    @ApiOperation(value = "更新一条日志")
    public JsonRequest<Integer> updateOneLog(
            @ApiParam(value = "待修改的日志信息", required = true)
            @RequestBody Log log) {
        return logService.updateOneLog(log);
    }

    /**
     * 批量删除日志
     *
     * @param ids 日志ID
     * @return JSON
     */
    @DeleteMapping
    @ApiOperation(value = "批量删除日志")
    public JsonRequest<Integer> deleteLog(
            @ApiParam(value = "日志ID", required = true)
            @RequestBody List<String> ids) {
        return logService.deleteLog(ids);
    }
}
